package utils;

import java.util.ArrayList;
import java.util.List;
import myinterface.INoeud;


public class Polygon implements INoeud{

	private int id;
	private List<Point> poly;
	private List<Integer> cheminSortie;
	private String type ;
	
	public Polygon(){
		this.poly = new ArrayList<Point>();
		this.cheminSortie = new ArrayList<Integer>();
	}
	public Polygon(int id,List<Point> poly, String type,List<Integer> segments){
		this.id = id;
		this.poly = poly;	
		this.type = type;
		this.cheminSortie = segments;
	}

	public Polygon(int id,List<Point> poly, String type){
		this.id = id;
		this.poly = poly;	
		this.type = type;
		this.cheminSortie = new ArrayList<Integer>();
	}
	public List<Point> getPoly() {
		return poly;
	}

	public void setPoly(List<Point> poly) {
		this.poly = poly;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	
	
	public List<Integer> getCheminSortie() {
		return cheminSortie;
	}

	public void setCheminSortie(List<Integer> cheminSortie) {
		this.cheminSortie = cheminSortie;
	}

	public void addCheminSortie(Segment s){
		this.cheminSortie.add(s.getId());
	}
	
	public void addAllChemin(List<Segment> ss){
		for(Segment s : ss)
			addCheminSortie(s);
	}
	
	public static List<Integer> polyToId(List<Polygon> poly){
		List<Integer> list = new ArrayList<Integer>();
		for(Polygon p : poly)
			list.add(p.id);
		
		return list;
	}
	
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Polygon other = (Polygon) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public String toString(){
		StringBuffer st = new StringBuffer("\t<polygone id=\""+this.id+"\" type=\""
	+this.type+"\">\n\n");
		
		for(Point p : poly)
			st.append("\t\t" +p.toString() +"\n");
		
		for(Integer s : cheminSortie)
			st.append("\n\t\t<chemin id=\""+ s +"\"/>");
		
		
		st.append("\n\n\t</polygone>");
		return st.toString();
	}

	@Override
	public List<Integer> getChemin() {
		return cheminSortie;
	}
	
	public void addPoint(Point point) {
		this.poly.add(point);
	}
	
	
	
}
